package com.fr.lintcode;

import org.junit.Test;

/**
*作者：furong
*日期：2017年1月13日
*时间：下午3:43:02
*/
public class Q35 {
    /**
     * @param head: The head of linked list.
     * @return: The new head of reversed linked list.
     */
    public ListNode reverse(ListNode head) {
        ListNode p = null;
        while (head != null) {
            ListNode tmp = head.next;
            head.next = p;
            p = head;
            head = tmp;
        }
        return p;
    }

    @Test
    public void testA() {
        ListNode head = new ListNode(1);
        ListNode l1 = new ListNode(2);
        ListNode l2 = new ListNode(3);
        ListNode l3 = new ListNode(4);
        ListNode l4 = new ListNode(5);
        ListNode l5 = new ListNode(3);
        ListNode l6 = new ListNode(2);
        head.next = l1;
        l1.next = l2;
        l2.next = l3;
        l3.next = l4;
        l4.next = l5;
        l5.next = l6;
        System.out.println(head);
        ListNode rs = reverse(head);
        System.out.println(rs);
    }
}
